//  -----------------------------------------------------------------------------------------------//
//   This file is part of SvnExternalUpdater                                                               //
//   Copyright (C)2008 Romain Verdier ( romain@codingly.com )                                      //
//                                                                                                 //
//   This program is free software; you can redistribute it and/or modify it under the terms       //
//   of the GNU General Public License as published by the Free Software Foundation; either        //
//   version 2 of the License, or (at your option) any later version. This program is distributed  //
//   in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied        //
//   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public  //
//   License for more details.                                                                     //
//                                                                                                 //
//   You should have received a copy of the GNU General Public License along with this program; if //
//   not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. or  //
//   see http://www.fsf.org/licensing/licenses/gpl.html                                            //
//  -----------------------------------------------------------------------------------------------//
using Codingly.SvnExternalUpdater.Core;
using Codingly.SvnExternalUpdater.Core.Services;
using Codingly.SvnExternalUpdater.Layout;
using Codingly.SvnExternalUpdater.Mvp;
using Codingly.SvnExternalUpdater.Presenters;
using Codingly.SvnExternalUpdater.Services;
using Codingly.SvnExternalUpdater.Views;
using Common.Logging;
using Ninject.Modules;

namespace Codingly.SvnExternalUpdater
{
    /// <summary>
    /// Main module for IoC
    /// </summary>
    public class MainModule : NinjectModule
    {
        private readonly ILog log = LogManager.GetLogger<MainModule>();

        public override void Load()
        {
            BindApplicationServices();
            BindServices();
            BindViews();
            BindPresenters();
        }

        private void BindApplicationServices()
        {
            log.Info("Binding application services");
            Bind<IPresenterProvider>().To<PresenterProvider>();
        }

        private void BindPresenters()
        {
            log.Info("Binding presenters");
            Bind<MainPresenter>().ToSelf().InTransientScope();
            Bind<AboutPresenter>().ToSelf().InTransientScope();
            Bind<ConfigurationPresenter>().ToSelf().InTransientScope();
            Bind<ProjectPresenter>().ToSelf().InTransientScope();
            Bind<ExternalPresenter>().ToSelf().InTransientScope();
        }

        private void BindServices()
        {
            log.Info("Binding services");
            Bind<IConfigurationService>().ToProvider<ConfigurationProvider>().InTransientScope();
            Bind<IUserConfigurationService>().To<UserConfigurationService>().InTransientScope();
            Bind<IVcsService>().To<SvnService>().InTransientScope();
            Bind<LayoutManager>().ToSelf().InSingletonScope();
            Bind<IMonitoringService>().To<MonitoringService>().InSingletonScope();
            Bind<ITortoiseService>().To<TortoiseService>().InSingletonScope();
            Bind<IFileSystemService>().To<FileSystemService>().InSingletonScope();
        }

        private void BindViews()
        {
            log.Info("Binding views");
            Bind<IMainView>().To<MainView>().InTransientScope();
            Bind<IAboutView>().To<AboutView>().InTransientScope();
            Bind<IConfigurationView>().To<ConfigurationView>().InTransientScope();
            Bind<IProjectView>().To<ProjectView>().InTransientScope();
            Bind<IExternalView>().To<ExternalView>().InTransientScope();
        }
    }
}